<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<script type="text/javascript" >

$(function(){
	$('#orgTree').tree({
		url: ctx + '/sm/Org!findChildTree.action?_json=json',
        fit: true,
        idField: 'id',
        treeField: 'text'
	});
	
	
	$('#orgAdd').bind('click',function(){
		var row = $('#orgTree').tree('getSelected');
		//console.log(row);
		if (!row) {
			$.messager.show({
				msg : '请选择一条数据'
			});
			return false;
		}
		//console.log(row);
		CQOA.load('extendDiv',ctx+'/sm/Org!operate.action',{'entity.upId':row.id},function(){
			CQOA.hideDiv('mainDiv');
			CQOA.showDiv('extendDiv');
		});
	});
	$('#orgEdit').bind('click',function(){
		var row = $('#orgTree').tree('getSelected');
		if (!row) {
			$.messager.show({
				msg : '请选择一条数据'
			});
			return false;
		}
		CQOA.load('extendDiv',ctx+'/sm/Org!operate.action',{'entity.sid':row.id},function(){
			CQOA.hideDiv('mainDiv');
			CQOA.showDiv('extendDiv');
		});
	});
	$('#orgDel').bind('click',function(){
		var row = $('#orgTree').tree('getSelected');
		if (!row) {
			$.messager.show({
				msg : '请选择一条数据'
			});
			return false;
		}
		$.messager.confirm('提示信息','你确定要删除这条数据?',function(s){
			if(s){
				postcommit(ctx+'/sm/Org!delete.action',{'entity.sid':row.id},function(o){
					if(o.success){
						$('#orgTree').tree('reload',$('#orgTree').tree('getParent',row.target).target);
					}
					$.messager.show({
						msg : o.msg
					});
				});
			}
		});
	});
	
});


function comeback(){
	CQOA.hideDiv('extendDiv');
	CQOA.showDiv('mainDiv');
};

function org_save(){
	var isUpdate = false;
	if($('#orgSid').val()!=''){
		isUpdate =true;
	}
	CQOA.formSubmit($('#orgOperateForm'),ctx+'/sm/Org!save.action',function(o){
		if(o.success){
			comeback();
			if(isUpdate){
				var thisRow = $('#orgTree').tree('getSelected');
				var root = $('#orgTree').tree('getRoot');
			    if(thisRow.id==root.id){
			    	$('#orgTree').tree('reload');
			    }else{
			    	$('#orgTree').tree('reload',$('#orgTree').tree('getParent',thisRow.target).target);
			    }
			}else{
				$('#orgTree').tree('reload',$('#orgTree').tree('getSelected').target);
			}
			
		}
		$.messager.show({
			msg : o.msg
		});
	},{});
};



</script>
<div id="mainDiv" class="easyui-layout" fit="true" border="false">
	        <div id="easyui-title" style="display:none">
	            	部门设置
	        </div>
            <div class="top_toolbar_div" region="north" border="false">                
                <div id="button_index" class="top_toolbar_button_div" border="false">
                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" id="orgAdd">新增</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" id="orgEdit">修改</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" id="orgDel">删除</a>
                </div>
            </div>
            <div  region="center" border="false">
	          <div class="main_content_div" style="width: 95%; height: 100%;overflow: auto;padding-top: 10px;padding-left: 10px;"; region="center" border="false">
               		<ul id="orgTree" class="easyui-tree"></ul>
              </div>
           </div>
</div>
<div id="extendDiv" class="easyui-panel" style="display:none;" fit="true" border="false"></div>


